package com.kaifamiao.advice;

import org.aspectj.lang.JoinPoint;

import java.util.Arrays;

/**
 * @author lucien-ma
 * @date 2021/8/27
 * @apiNote
 */
public class TransactionAdvice {

    private String className;

    private String methodName;

    public void before(JoinPoint joinPoint) {
        className = joinPoint.getTarget().getClass().getSimpleName();
        methodName = joinPoint.getSignature().getName();
        Object[] args = joinPoint.getArgs();
        System.out.println(className + "." + methodName + "开启事务，参数是：" + Arrays.toString(args));
    }

    public void commit(JoinPoint joinPoint) {
        System.out.println(className + "." + methodName + "提交事务");
    }

    public void rollback(JoinPoint joinPoint) {
        System.out.println(className + "." + methodName + "回滚事务");
    }
}
